package com.itheima.demo03;

public class BasicSearchDemo02 {
    public static void main(String[] args) {
        //1.基本查询/按顺序查找
        //需求：查找某个值是否存在，存在返回索引
        int[] arr = {2, 33, 3, 12, 34, 56, 123, 344, 124};
        int number = 34;
        System.out.println(basicSearch(arr, number));

    }

    public static int basicSearch(int[] arr, int number) {
        //遍历每一个元素和number比较 如果相等 就返回索引值
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return i;
            }
        }

        return -1;
    }

}
